package service;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import entity.profit;
import util.DBHelper;

public class profit_service
{
	private Connection conn;
	private PreparedStatement stmt = null;
	private CallableStatement cs = null;
	private ResultSet rs;
	private String sql;
	private ArrayList<profit> list;
	private profit pf;
	
	public ArrayList<profit> getProfit()
	{
		list = new ArrayList<profit>();
		
		try
		{ 
			conn = DBHelper.getConnection();
			sql = "CALL sp_getProfit()";
			cs = conn.prepareCall(sql);
			cs.execute();
			rs = cs.getResultSet();

			while(rs.next())
			{
//				System.out.println("--------rs.next--------");
			
				pf = new profit();
				pf.setGoodsname(rs.getString("goods_name"));
				pf.setGoodsID(rs.getString("goods_id"));
				pf.setPf_id(rs.getInt("pf_id"));
				pf.setSell_count(rs.getInt("sell_count"));
				pf.setTrading_times(rs.getInt("trading_times"));
				pf.setProfits(rs.getInt("profit"));
				
				//向list中添加对象
				list.add(pf);
			}
		} 
		catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
//		System.out.println("--------here--------");
		
		return list;
	}
}
